<html>
<head><meta charset="utf-8"><title>why does bbqueue use GenericArray? · t-lang · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/index.html">t-lang</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html">why does bbqueue use GenericArray?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="203108542"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203108542" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203108542">(Jul 07 2020 at 14:21)</a>:</h4>
<p>Is there any particular reason for these to require a <code>GenericArray</code> instead of consuming some <code>&amp;mut [MaybeUninit&lt;u8&gt;]</code> from the caller to allocate into?</p>



<a name="203109896"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203109896" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203109896">(Jul 07 2020 at 14:31)</a>:</h4>
<p><span class="user-mention" data-user-id="229913">@HeroicKatora</span> that sounds like the same question as "why use arrays when you could use slices" — is that the intent?</p>



<a name="203121745"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203121745" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203121745">(Jul 07 2020 at 15:56)</a>:</h4>
<p>Not really. I intended to say that const generics surely are one way to solve thes problems but alternatives exist. For example, an allocator API that wasn't necessarily global—but e.g. stack bound—would allow embedded to utilize the standard containers which are currently heavily gated in <code>alloc</code>, and that is the underlying cause why that part of the ecosystem relies on arrays so much. And if those were available I doubt there would be any need for this in the first place. I do see the prevalance of <code>GenericArray</code> as a kind of XY problem tbh. And using <code>[MaybeUninit&lt;u8&gt;]</code> is a way to make up for this via a sort of local allocator. Plus it requires <code>unsafe</code> and that is scary.</p>



<a name="203121951"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203121951" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203121951">(Jul 07 2020 at 15:58)</a>:</h4>
<p>But i digress, probably should have forked the thread instead..</p>



<a name="203122565"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203122565" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203122565">(Jul 07 2020 at 16:03)</a>:</h4>
<p><span class="user-mention silent" data-user-id="229913">HeroicKatora</span> <a href="#narrow/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F/near/203121951">said</a>:</p>
<blockquote>
<p>But i digress, probably should have forked the thread instead..</p>
</blockquote>
<p>Done <span aria-label="wink" class="emoji emoji-1f609" role="img" title="wink">:wink:</span></p>



<a name="203124114"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203124114" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203124114">(Jul 07 2020 at 16:12)</a>:</h4>
<p>(deleted)</p>



<a name="203212922"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203212922" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203212922">(Jul 07 2020 at 22:51)</a>:</h4>
<p>Hey <span class="user-mention" data-user-id="229913">@HeroicKatora</span>, I'm the author of bbqueue</p>



<a name="203213057"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203213057" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203213057">(Jul 07 2020 at 22:52)</a>:</h4>
<p>Generally the answer is: it was way easier to keep the scary unsafe code inside of bbqueue, instead of forcing the user to (usually) use unsafe to pass a static mut slice into the constructor.</p>



<a name="203213097"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203213097" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203213097">(Jul 07 2020 at 22:53)</a>:</h4>
<p>The most heavy use case of bbqueue is for embedded DMA, where slices generally have to be <code>'static</code>, as there is no reliable way to give ownership of data to the hardware itself.</p>



<a name="203213179"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203213179" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203213179">(Jul 07 2020 at 22:54)</a>:</h4>
<p>If you look at earlier versions of bbqueue, it actually did take a &amp;mut [u8], though it also meant I needed to provide a macro to encapsulate the creation of the item.</p>



<a name="203213191"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203213191" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203213191">(Jul 07 2020 at 22:54)</a>:</h4>
<p>Feel free to @ me here if you have any other questions, or I also hang out on the rust-embedded matrix server.</p>



<a name="203213375"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203213375" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203213375">(Jul 07 2020 at 22:57)</a>:</h4>
<p>Once const generic arrays land, I very much would like to switch bbqueue over to that instead. Most of the unsafe and even most of the code itself is to work around being able to have:</p>
<ul>
<li>const/static constructors</li>
<li>variable size payloads</li>
</ul>



<a name="203213504"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203213504" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203213504">(Jul 07 2020 at 22:59)</a>:</h4>
<p>Though, likely it will always require some unsafe, because there is a special runtime checked slice ownership, because producer and consumer access is unsynchronized, and I want the grants to have non-linear ownership lifetimes without heap allocation (e.g. you can store the grant somewhere longer than the lifetime of the borrow of the producer/consumer).</p>



<a name="203213682"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203213682" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203213682">(Jul 07 2020 at 23:01)</a>:</h4>
<p>(I just realized this conversation came from the "stable subset" thread, which is probably how you heard about bbqueue)</p>



<a name="203254772"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203254772" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203254772">(Jul 08 2020 at 11:07)</a>:</h4>
<blockquote>
<p>The most heavy use case of bbqueue is for embedded DMA, where slices generally have to be 'static, as there is no reliable way to give ownership of data to the hardware itself.</p>
</blockquote>
<p>Does that mean using the linker to place the bbqueue at the right address? Because that would sound a whole lot scarier than linking a slice and using that.</p>



<a name="203254941"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203254941" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203254941">(Jul 08 2020 at 11:09)</a>:</h4>
<p><span class="user-mention" data-user-id="228912">@James Munns</span> The need to use <code>unsafe</code> for all of this is also heavily connected to the allocator problem: The task of giving you a <code>&amp;'static mut [u8]</code> is _exactly_ what the allocator would encapsulate into a safe interface. No-one questsions vec![] to be safe to use either, of course a proper redesign would make it fallible so that you'd reserve your mutable slice once at program start and then pass it around but those are minor details.</p>



<a name="203255050"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203255050" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203255050">(Jul 08 2020 at 11:11)</a>:</h4>
<p>Same thing for runtime checked slice ownership, that's sounds very much like a specialized allocator or a SlotMap would solve. Which also is gated by being able to use allocated datastructures despite the lack of a global allocator.</p>



<a name="203262927"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203262927" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203262927">(Jul 08 2020 at 12:50)</a>:</h4>
<p><span class="user-mention" data-user-id="228912">@James Munns</span> could you go into a little more detail about the DMA? In your scenario, how is the DMA signaled to start and stop, and also does the CPU continue to run while the DMA is occurring?</p>



<a name="203297455"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203297455" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203297455">(Jul 08 2020 at 17:31)</a>:</h4>
<p><span class="user-mention" data-user-id="229913">@HeroicKatora</span> so, bbqueue is sort of like a specific use case allocator, however it is generally deterministic (due to to bounded access time with no garbage collection). You're right, an allocator is also another way to handle this concern, if you have one, which I don't typically.</p>



<a name="203297633"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203297633" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203297633">(Jul 08 2020 at 17:32)</a>:</h4>
<p>The placement of bbqueue isn't managed by the linker, but rather by existing at <code>static</code> scope, we can guarantee the buffer that backs bbqueue is always valid. This wouldn't be true for example when using a stack allocated frame.</p>



<a name="203297700"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203297700" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203297700">(Jul 08 2020 at 17:33)</a>:</h4>
<p>For example, if you stack allocate space, start a DMA transaction, but it keeps running after you've returned from that stack frame. In that case, the DMA will potentially corrupt a later stack frame!</p>



<a name="203297830"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203297830" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203297830">(Jul 08 2020 at 17:34)</a>:</h4>
<p>There are some ways to mitigate this (halt the DMA transaction on <code>drop</code>), however <code>mem::forget</code> is still a thing, so we can't guarantee the destructor will run. This is very similar to the issues @boats has raised re: io_uring and ringbahn.</p>



<a name="203297865"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203297865" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203297865">(Jul 08 2020 at 17:34)</a>:</h4>
<p>However for embedded: It's the hardware that needs to "own" the buffer, rather than the kernel.</p>



<a name="203298094"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203298094" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203298094">(Jul 08 2020 at 17:36)</a>:</h4>
<p><span class="user-mention" data-user-id="224471">@Lokathor</span> I'm speaking about DMA in general, however I most commonly work with Arm Cortex-M devices. In this case, DMA is usually started by configuring a memory mapped (MMIO) peripheral, typically giving it a "start pointer" and a "number of bytes". It then copies from/to that address range, in parallel with the main CPU.</p>



<a name="203298150"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203298150" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203298150">(Jul 08 2020 at 17:37)</a>:</h4>
<p>Ah okay, so this is the "DMA is another thread" model, basically?</p>



<a name="203298158"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203298158" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203298158">(Jul 08 2020 at 17:37)</a>:</h4>
<p>Since the "control flow" of the hardware is totally orthogonal to the control flow of the software, and the hardware knows nothing of lifetimes etc., we need to carefully work around that.</p>



<a name="203298165"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203298165" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203298165">(Jul 08 2020 at 17:37)</a>:</h4>
<p>Yeah! That's a good analogy.</p>



<a name="203298188"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203298188" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203298188">(Jul 08 2020 at 17:37)</a>:</h4>
<p>But also "another thread written in C that does whatever it feels like" :D</p>



<a name="203298330"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203298330" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203298330">(Jul 08 2020 at 17:38)</a>:</h4>
<p>I've heard of that but never used it myself. On GBA the DMA unit cuts in and the CPU is halted while DMA unit is active (makes it generally much simpler to reason about!)</p>



<a name="203298331"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203298331" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203298331">(Jul 08 2020 at 17:38)</a>:</h4>
<p>That's why bbqueue is <code>Send</code>able: You can have one half of the Producer/Consumer pair in different "thread" contexts, including:</p>
<ul>
<li>The main program</li>
<li>Interrupt context</li>
<li>DMA context</li>
</ul>
<p>All of which act like unsynchronized "threads", essentially.</p>



<a name="203298357"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203298357" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203298357">(Jul 08 2020 at 17:38)</a>:</h4>
<p>Ahh, what's the point of the DMA then? Does it copy faster than mem to mem transfers?</p>



<a name="203298376"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203298376" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203298376">(Jul 08 2020 at 17:39)</a>:</h4>
<p>yeah about 2x as fast</p>



<a name="203298418"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203298418" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203298418">(Jul 08 2020 at 17:39)</a>:</h4>
<p>Cortex-M typically has a number of memory buses, when multiple items (CPU, DMA, Flash controller) want to use the same memory bus, the hardware round robin arbitrates the different actors</p>



<a name="203298439"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203298439" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203298439">(Jul 08 2020 at 17:39)</a>:</h4>
<p>When different parts use different busses, they can run totally in parallel.</p>



<a name="203298563"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203298563" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203298563">(Jul 08 2020 at 17:40)</a>:</h4>
<p>the poor GBA is from 2003 and using tech that's mostly from like 1995 or so ;_;</p>



<a name="203298637"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203298637" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203298637">(Jul 08 2020 at 17:41)</a>:</h4>
<p>We're all playing with concepts that were invented some time between 1960 and 1985, anyway :)</p>



<a name="203298715"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203298715" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203298715">(Jul 08 2020 at 17:42)</a>:</h4>
<p>bbqueue is an iterative improvement over bipbuffers, which are from the 80s/90s?</p>



<a name="203298743"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203298743" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203298743">(Jul 08 2020 at 17:42)</a>:</h4>
<p>Though Rust makes it easier to enforce invariants through the type system and ownership model.</p>



<a name="203298881"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203298881" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203298881">(Jul 08 2020 at 17:43)</a>:</h4>
<p><span class="user-mention" data-user-id="229913">@HeroicKatora</span> if you're interested, we did a write up around the time we designed bbqueue: <a href="https://ferrous-systems.com/blog/lock-free-ring-buffer/">https://ferrous-systems.com/blog/lock-free-ring-buffer/</a></p>



<a name="203299151"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203299151" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203299151">(Jul 08 2020 at 17:45)</a>:</h4>
<p>fwiw I do plan to make a version of bbqueue that can be heap allocated, so you don't need the nasty <code>static</code> for <code>std</code> (or <code>alloc</code>) programs, though I don't particularly see the need for embedded systems where the buffer is preallocated anyway.</p>



<a name="203299306"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203299306" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203299306">(Jul 08 2020 at 17:46)</a>:</h4>
<p>If you're interested, here's a driver that uses a pair of BBQueues to implement a hardware accelerated/managed serial port, abstracting the full hardware into basically just an input stream and output stream:</p>
<p><a href="https://github.com/jamesmunns/home-fleet/tree/main/embedded/fleet-uarte">https://github.com/jamesmunns/home-fleet/tree/main/embedded/fleet-uarte</a></p>



<a name="203299549"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203299549" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203299549">(Jul 08 2020 at 17:48)</a>:</h4>
<p>It does all of:</p>
<ul>
<li>Automatically draining outgoing bytes using DMA transactions that "auto reload" until the outgoing queue is empty</li>
<li>Uses DMA to receive incoming bytes, will automatically flush and start a new DMA transaction if the buffer is full</li>
<li>If there have been no bytes over the wire for the last N microseconds, it "flushes" the input buffer to make it available to the user</li>
</ul>



<a name="203299737"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203299737" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203299737">(Jul 08 2020 at 17:49)</a>:</h4>
<p>Here's a fully hardware accelerated loopback example (<a href="https://github.com/jamesmunns/home-fleet/blob/main/embedded/test-modem/src/main.rs#L159-L174">https://github.com/jamesmunns/home-fleet/blob/main/embedded/test-modem/src/main.rs#L159-L174</a>):</p>
<div class="codehilite"><pre><span></span><code><span class="k">loop</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">if</span><span class="w"> </span><span class="kd">let</span><span class="w"> </span><span class="nb">Ok</span><span class="p">(</span><span class="n">rgr</span><span class="p">)</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">uarte_app</span><span class="p">.</span><span class="n">read</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">len</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">rgr</span><span class="p">.</span><span class="n">len</span><span class="p">();</span><span class="w"></span>
<span class="w">        </span><span class="k">if</span><span class="w"> </span><span class="kd">let</span><span class="w"> </span><span class="nb">Ok</span><span class="p">(</span><span class="k">mut</span><span class="w"> </span><span class="n">wgr</span><span class="p">)</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">uarte_app</span><span class="p">.</span><span class="n">write_grant</span><span class="p">(</span><span class="n">len</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">            </span><span class="n">wgr</span><span class="p">.</span><span class="n">copy_from_slice</span><span class="p">(</span><span class="o">&amp;</span><span class="n">rgr</span><span class="p">);</span><span class="w"></span>
<span class="w">            </span><span class="n">wgr</span><span class="p">.</span><span class="n">commit</span><span class="p">(</span><span class="n">len</span><span class="p">);</span><span class="w"></span>
<span class="w">        </span><span class="p">}</span><span class="w"></span>
<span class="w">        </span><span class="n">rgr</span><span class="p">.</span><span class="n">release</span><span class="p">(</span><span class="n">len</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="203299823"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203299823" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203299823">(Jul 08 2020 at 17:50)</a>:</h4>
<p>Well, I guess the CPU copies from the RX buffer to the TX buffer, but the actual RX and TX are handled by hardware/dma/interrupts/bbqueue</p>



<a name="203300059"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203300059" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203300059">(Jul 08 2020 at 17:52)</a>:</h4>
<p><span class="user-mention silent" data-user-id="228912">James Munns</span> <a href="#narrow/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F/near/203297455">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="229913">HeroicKatora</span> so, bbqueue is sort of like a specific use case allocator, however it is generally deterministic (due to to bounded access time with no garbage collection). You're right, an allocator is also another way to handle this concern, if you have one, which I don't typically.</p>
</blockquote>
<p>I suppose more specifically, bbqueue is a "FIFO allocator"</p>



<a name="203300810"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203300810" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203300810">(Jul 08 2020 at 17:59)</a>:</h4>
<p>Okay, thanks for the large allocation of an explanation <span aria-label="slight smile" class="emoji emoji-1f642" role="img" title="slight smile">:slight_smile:</span></p>



<a name="203300858"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203300858" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203300858">(Jul 08 2020 at 17:59)</a>:</h4>
<p>However, I'm still not sure why bbqueue is its own allocator instead of using some underlying one.</p>



<a name="203301296"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203301296" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203301296">(Jul 08 2020 at 18:03)</a>:</h4>
<p>In particular even without <code>GlobalAlloc</code>, <code>alloc</code>, I can embed a raw chunk of memory in the program image and do a sound bump allocator on top of it. This is similar to the technique of using GenericArray but it doesn't require const generics. Then I could still construct the bbqueue at runtime, using that static chunks of memory to allocate the two queues which will always succeed if its the only use of that memory. It's never returned so a bump allocator is fine as well. I know such a bump allocator can be done because I've already written the crate when doing no_std networking (now used in a riscv baremetal or so I've heard).</p>



<a name="203301490"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203301490" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203301490">(Jul 08 2020 at 18:04)</a>:</h4>
<p>This would fully decouple the allocator portion, the embedding of raw memory in the binary, and the bbqueue as a composed allocator while simultaneously making const generics unecessary.</p>



<a name="203301502"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203301502" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203301502">(Jul 08 2020 at 18:04)</a>:</h4>
<p><span class="user-mention" data-user-id="228912">@James Munns</span> I think it's worth mentioning that a similar concept, "the kernel owns the buffer", has been discussed in the context of <code>io_uring</code> implementations for Rust.</p>



<a name="203302287"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203302287" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203302287">(Jul 08 2020 at 18:11)</a>:</h4>
<p>(deleted)</p>



<a name="203302510"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203302510" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203302510">(Jul 08 2020 at 18:13)</a>:</h4>
<p><span class="user-mention" data-user-id="228912">@James Munns</span>  the one instances that I know of where my technique becomes more complicated is if you need to have your meta data appear inline of the data buffer. It still works but you'd have to do some workarounds of unsizing your type instead. I can show you an example if you're interested.</p>



<a name="203302634"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203302634" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203302634">(Jul 08 2020 at 18:14)</a>:</h4>
<p>You can only implement an allocator in nightly, currently.</p>



<a name="203302691"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203302691" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203302691">(Jul 08 2020 at 18:15)</a>:</h4>
<p>You can implement <code>GlobalAlloc</code> only on nightly, that doesn't stop you from defining your own allocator-like interface.</p>



<a name="203302716"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203302716" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203302716">(Jul 08 2020 at 18:15)</a>:</h4>
<p>Like bbqueue? :D</p>



<a name="203302736"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203302736" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203302736">(Jul 08 2020 at 18:15)</a>:</h4>
<p>Allocators are less fun when you can't use all of collections with them.</p>



<a name="203302740"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203302740" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203302740">(Jul 08 2020 at 18:15)</a>:</h4>
<p>More general and without GenericArray ;)</p>



<a name="203302772"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203302772" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203302772">(Jul 08 2020 at 18:15)</a>:</h4>
<p>Like I said, the choice of GenericArray/Const Generics is a UX decision.</p>



<a name="203302826"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203302826" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203302826">(Jul 08 2020 at 18:16)</a>:</h4>
<p>Previous versions took a user provided buffer, but I decided I liked that less.</p>



<a name="203302842"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203302842" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203302842">(Jul 08 2020 at 18:16)</a>:</h4>
<p>Your tastes may vary.</p>



<a name="203302865"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203302865" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203302865">(Jul 08 2020 at 18:16)</a>:</h4>
<p>I can show you how to avoid the GenericArray even without require the user to give a layout</p>



<a name="203302877"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203302877" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203302877">(Jul 08 2020 at 18:16)</a>:</h4>
<p><span class="user-mention" data-user-id="239881">@Josh Triplett</span> yup! I think it's the same concern here.</p>



<a name="203302878"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203302878" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203302878">(Jul 08 2020 at 18:16)</a>:</h4>
<p>It will be like magic ;)</p>



<a name="203302886"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203302886" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203302886">(Jul 08 2020 at 18:16)</a>:</h4>
<p>I mentioned that above.</p>



<a name="203303096"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203303096" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203303096">(Jul 08 2020 at 18:18)</a>:</h4>
<p>Concept executed here: <a href="https://github.com/HeroicKatora/static-alloc/tree/master/static-alloc">https://github.com/HeroicKatora/static-alloc/tree/master/static-alloc</a><br>
No GenericArray, instead the user supplies any type that is as large as the buffer they want. A useful choice is of course using <code>[u8; N]</code> but anything works. Since this doesn't have a const generic but only a generic type parameter, it fully works on stable.</p>



<a name="203303127"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203303127" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203303127">(Jul 08 2020 at 18:18)</a>:</h4>
<p>minor nit: GlobalAlloc trait and global_allocator attribute are both stable, it's just that alloc_error_handler isn't stable</p>



<a name="203303230"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203303230" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203303230">(Jul 08 2020 at 18:19)</a>:</h4>
<p>Thanks, <span class="user-mention" data-user-id="224471">@Lokathor</span> . Yeah, the real deal is that you wouldn't want a global instance but <code>extern crate alloc</code> requires one. You'd only want the interface.</p>



<a name="203303339"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203303339" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203303339">(Jul 08 2020 at 18:20)</a>:</h4>
<p>there's probably a lot to dislike about <code>alloc</code> ;P</p>



<a name="203307239"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203307239" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203307239">(Jul 08 2020 at 18:52)</a>:</h4>
<p>I'll check that out, thanks!</p>



<a name="203440751"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203440751" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203440751">(Jul 09 2020 at 21:05)</a>:</h4>
<p><span class="user-mention" data-user-id="229913">@HeroicKatora</span> btw, <a href="https://github.com/rust-lang/rust/pull/60667">https://github.com/rust-lang/rust/pull/60667</a> has landed (I saw some notes about unsized support in static-alloc)</p>



<a name="203440928"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203440928" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203440928">(Jul 09 2020 at 21:06)</a>:</h4>
<p>Or rather, <a href="https://github.com/rust-lang/rust/pull/68234">https://github.com/rust-lang/rust/pull/68234</a></p>



<a name="203441111"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203441111" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203441111">(Jul 09 2020 at 21:08)</a>:</h4>
<p>Thanks for the notice! I might have missed the stabilization. I'll have a look.</p>



<a name="203441938"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203441938" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203441938">(Jul 09 2020 at 21:17)</a>:</h4>
<p>Is there any benefit to marking a bump alloc as <code>#[global_allocator]</code> without <code>extern crate alloc</code>?</p>



<a name="203442768"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203442768" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203442768">(Jul 09 2020 at 21:24)</a>:</h4>
<p>Also worth noting that I don't think <code>static-alloc</code> would support <code>thumbv6</code> targets, as they don't have compare and swap (bbqueue does support those targets - with a target specific critical section)</p>



<a name="203443266"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203443266" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203443266">(Jul 09 2020 at 21:29)</a>:</h4>
<p><span class="user-mention silent" data-user-id="228912">James Munns</span> <a href="#narrow/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F/near/203441938">said</a>:</p>
<blockquote>
<p>Is there any benefit to marking a bump alloc as <code>#[global_allocator]</code> without <code>extern crate alloc</code>?</p>
</blockquote>
<p>I don't think so, no. The example was mainly targetted at <code>no_std</code> with <code>alloc</code>. The rest of the interface is for without <code>alloc</code>. Yes, I noticed that difference. Is there anything in particular I should avoid in the critical sections, if I were to change all atomic operations to use one?</p>



<a name="203443406"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203443406" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203443406">(Jul 09 2020 at 21:31)</a>:</h4>
<p>Unfortunately critical sections are generally non portable - they are target specific.</p>



<a name="203443453"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203443453" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203443453">(Jul 09 2020 at 21:31)</a>:</h4>
<p>For cortex-m targets, it generally means disabling interrupts, because then you know preemption is impossible</p>



<a name="203443482"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203443482" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203443482">(Jul 09 2020 at 21:31)</a>:</h4>
<p>We have a shim around this that makes it reasonably easier to maintain in bbqueue</p>



<a name="203443569"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203443569" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203443569">(Jul 09 2020 at 21:32)</a>:</h4>
<p><a href="https://github.com/jamesmunns/bbqueue/blob/master/core/src/bbbuffer.rs#L983-L1037">https://github.com/jamesmunns/bbqueue/blob/master/core/src/bbbuffer.rs#L983-L1037</a></p>



<a name="203443834"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203443834" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203443834">(Jul 09 2020 at 21:34)</a>:</h4>
<p>I'm not volunteering at the moment, but would it be reasonable/feasible/interesting to implement a more complicated allocator for <code>static-alloc</code>?</p>



<a name="203443846"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203443846" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203443846">(Jul 09 2020 at 21:34)</a>:</h4>
<p>e.g. a non-bump allocator?</p>



<a name="203444086"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203444086" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203444086">(Jul 09 2020 at 21:36)</a>:</h4>
<p>probably something like <a href="https://github.com/phil-opp/linked-list-allocator">https://github.com/phil-opp/linked-list-allocator</a></p>



<a name="203444193"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203444193" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203444193">(Jul 09 2020 at 21:38)</a>:</h4>
<p>Yes, it would. Although I would really recommend to only implement more complicated allocators as a non-<code>Sync</code> version and have them only run thread-local. Since you can of chunk the original bump allocator once when you start the program, and send each individual chunk to the thread that needs it. (Which is how safety critical programs handle allocation anyways if I am up-to-date).</p>



<a name="203444255"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203444255" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203444255">(Jul 09 2020 at 21:38)</a>:</h4>
<p>Depends on the industry :)</p>



<a name="203444334"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203444334" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203444334">(Jul 09 2020 at 21:39)</a>:</h4>
<p>You can reset the bump allocator if you are able to collect all using allocations and re-acquire a <code>&amp;mut _</code> to it</p>



<a name="203444459"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203444459" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203444459">(Jul 09 2020 at 21:40)</a>:</h4>
<p>Are you working in safety critical currently, btw?</p>



<a name="203444575"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203444575" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203444575">(Jul 09 2020 at 21:41)</a>:</h4>
<p>No, not currently. But I do certain things close to hardware and automation.<br>
But I would if given the chance and the time is right.</p>



<a name="203444928"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203444928" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203444928">(Jul 09 2020 at 21:44)</a>:</h4>
<p>Though I really, really like what I'm doing right now which is mainly performance oriented. As I've noted elsewhere there is an overlap between performance and safety critical in that safety most often also means predictable and predictable is very good for tuning. Evidence: seL4 is simultaneously highly secure, safe, and real-time capable, and has lower system call latency than many (most) alternatives.</p>



<a name="203444962"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203444962" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203444962">(Jul 09 2020 at 21:44)</a>:</h4>
<p>No worries, I was just wondering!</p>



<a name="203445088"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203445088" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203445088">(Jul 09 2020 at 21:45)</a>:</h4>
<p>(I'm trying to make safety critical Rust a thing, which is why I asked)</p>



<a name="203445696"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203445696" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203445696">(Jul 09 2020 at 21:50)</a>:</h4>
<p>Generally IMO, the places where allocators help the most in embedded are situations like:</p>
<ul>
<li>Boxed closures, which can be used as interrupt handlers with late assignment of resources</li>
<li>DMA, allowing for lifetimes that extend beyond regular control flow</li>
</ul>



<a name="203445776"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203445776" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203445776">(Jul 09 2020 at 21:51)</a>:</h4>
<p>The former I don't think is possible without global alloc, though maybe with unsized support you could do with <code>static-alloc</code>?</p>



<a name="203445849"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203445849" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203445849">(Jul 09 2020 at 21:51)</a>:</h4>
<p>DMA could definitely be possible, though you'd want to have reclaimable slices.</p>



<a name="203445971"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203445971" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203445971">(Jul 09 2020 at 21:52)</a>:</h4>
<p><a href="https://docs.rs/heapless/0.5.5/heapless/pool/struct.Pool.html">https://docs.rs/heapless/0.5.5/heapless/pool/struct.Pool.html</a> is useful for the latter, though you are fixed to a single T, unlike static-alloc (which can be wasteful with variable sized DMA transactions, e.g. radio frames that could be anywhere between 2-255 bytes)</p>



<a name="203446024"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203446024" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203446024">(Jul 09 2020 at 21:53)</a>:</h4>
<p>bbqueue is also designed to help with the latter, though it is restricted to byte arrays, and has FIFO semantics, which is usually okay, but not always.</p>



<a name="203446025"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203446025" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203446025">(Jul 09 2020 at 21:53)</a>:</h4>
<p>The first case requires the container to <code>Unsize</code> the exact type to a dyn trait object. This is, apart from nightly, only possible for the standard types and without alloc that is specifically <code>&amp;_</code> and <code>&amp;mut _</code>.</p>



<a name="203446062"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203446062" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203446062">(Jul 09 2020 at 21:53)</a>:</h4>
<p>aw :/</p>



<a name="203446155"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203446155" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203446155">(Jul 09 2020 at 21:54)</a>:</h4>
<p>can you turn it into a dyn FnMut?</p>



<a name="203446166"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203446166" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203446166">(Jul 09 2020 at 21:54)</a>:</h4>
<p>and box that?</p>



<a name="203446176"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203446176" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203446176">(Jul 09 2020 at 21:54)</a>:</h4>
<p>You probably could do it with static-alloc though. You don't need to deallocate anything if you just reclaim all memory after you're done using the closure. That way, you avoid having to use any Box or other wrapper and can use <code>&amp;</code> just fine</p>



<a name="203446235"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203446235" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203446235">(Jul 09 2020 at 21:55)</a>:</h4>
<p>So, the typical workflow for interrupt handlers is to do something like:</p>
<ul>
<li>Set up some peripherals</li>
<li>"move" them into the interrupt handler</li>
</ul>



<a name="203446344"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203446344" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203446344">(Jul 09 2020 at 21:56)</a>:</h4>
<p>Because interrupts are essentially <code>fn()</code> (with no args or return value), you typically have to do something tricky to hand them "context".</p>



<a name="203446462"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203446462" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203446462">(Jul 09 2020 at 21:57)</a>:</h4>
<p>You know the patter to declare a variable and assign it in one branch?</p>
<div class="codehilite"><pre><span></span><code>let case_a;
let case_b;
let generic: &amp;dyn FnOnce();
if some_condition {
    case_a = creat_a();
    generic = &amp;case_a;
} else {
    case_b = creat_b();
    generic = &amp;case_b;
}
</code></pre></div>



<a name="203446541"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203446541" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203446541">(Jul 09 2020 at 21:58)</a>:</h4>
<p>You could probably do the same to get an unsized <code>&amp;dyn FnOnce()</code> while using <code>without_alloc::boxed::Box</code> to drop the closures after use.</p>



<a name="203446560"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203446560" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203446560">(Jul 09 2020 at 21:58)</a>:</h4>
<p>interesting</p>



<a name="203446615"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203446615" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203446615">(Jul 09 2020 at 21:59)</a>:</h4>
<p>If you replace <code>creat_a</code> with <code>local_bump_allocator.boxed(value)</code> (from the LocalAllocLeakExt trait)</p>



<a name="203446642"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203446642" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203446642">(Jul 09 2020 at 21:59)</a>:</h4>
<p>I'd have to store that somewhere, probably some kind of static AtomicPtr that nops if the ptr is null, and calls the closure as a <code>dyn FnMut()</code></p>



<a name="203446774"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203446774" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203446774">(Jul 09 2020 at 22:00)</a>:</h4>
<p>Yep, the hard part is getting the <code>&amp;'static mut dyn FnOnce()</code> to store in that.</p>



<a name="203446792"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203446792" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203446792">(Jul 09 2020 at 22:00)</a>:</h4>
<p>something like:</p>
<ul>
<li>static AtomicPtr::new(0)</li>
<li>on init: heap allocate closure, set atomicptr to closure ptr</li>
<li>on call: match on atomicptr, if null, nop, otherwise cast + call</li>
</ul>



<a name="203446989"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203446989" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203446989">(Jul 09 2020 at 22:02)</a>:</h4>
<p>Hm, so if you're fine with an <code>FnMut()</code> you can store it as a dyn trait ptr and call that directly without casting</p>



<a name="203447028"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203447028" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203447028">(Jul 09 2020 at 22:02)</a>:</h4>
<p>Yeah, most interrupts need to be called N times, so I assume I need a fnmut</p>



<a name="203447283"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203447283" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203447283">(Jul 09 2020 at 22:04)</a>:</h4>
<p>That should work out then. FnOnce requires either a value (which is unsized so you don't have it) or a Box (which requires alloc) so sadly that wouldn't work</p>



<a name="203447369"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203447369" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203447369">(Jul 09 2020 at 22:05)</a>:</h4>
<p>Really, you only need this if you want to swap interrupt handlers at runtime, otherwise we have other tricks to move data to handler context</p>



<a name="203447405"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203447405" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203447405">(Jul 09 2020 at 22:05)</a>:</h4>
<p><a href="https://therealprof.github.io/blog/interrupt-comparison/">https://therealprof.github.io/blog/interrupt-comparison/</a> is a good overview of the variety of tricks we have</p>



<a name="203447519"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203447519" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203447519">(Jul 09 2020 at 22:06)</a>:</h4>
<p>But all of them sort of fall over if you have different handlers that can be swapped at runtime, which is sometimes a thing you want to do, and might be more useful with async/await now working on core.</p>



<a name="203447531"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203447531" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203447531">(Jul 09 2020 at 22:07)</a>:</h4>
<p>but anyway, thanks for humoring me and answering all the questions :)</p>



<a name="203447724"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/203447724" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#203447724">(Jul 09 2020 at 22:08)</a>:</h4>
<p>Thanks for being interested and open to it as well.</p>



<a name="236922831"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/236922831" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#236922831">(May 01 2021 at 01:01)</a>:</h4>
<p>Waking up this thread a bit, but I wanted to see if this was still true <span class="user-mention" data-user-id="229913">@HeroicKatora</span>: <a href="https://docs.rs/static-alloc/0.2.2/static_alloc/bump/struct.Bump.html#limitations">https://docs.rs/static-alloc/0.2.2/static_alloc/bump/struct.Bump.html#limitations</a>, the mentioned method has now landed</p>



<a name="236922968"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/236922968" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#236922968">(May 01 2021 at 01:02)</a>:</h4>
<p>I'm attempting to have something like a:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">static</span><span class="w"> </span><span class="n">OMLF</span>: <span class="nc">OnceCell</span><span class="o">&lt;</span><span class="n">Mutex</span><span class="o">&lt;</span><span class="n">LeakBox</span><span class="o">&lt;'</span><span class="nb">static</span><span class="p">,</span><span class="w"> </span><span class="k">dyn</span><span class="w"> </span><span class="n">Future</span><span class="o">&lt;</span><span class="n">Output</span><span class="o">=</span><span class="p">()</span><span class="o">&gt;&gt;&gt;&gt;</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">OnceCell</span>::<span class="n">new</span><span class="p">();</span><span class="w"></span>
</code></pre></div>
<p>And tried to do this with the <a href="https://docs.rs/unsize/1.1.0/unsize/macro.Coercion.html">unsize</a> crate, but still ran into problems</p>



<a name="236929070"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/236929070" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#236929070">(May 01 2021 at 02:37)</a>:</h4>
<p>Ha Ha! I made it work, in probably a terrible way!</p>
<p><a href="https://github.com/jamesmunns/cassette/pull/3/files#diff-ed3100414beca7e0d41c4f7a0765209dd2430a54dc6f3287355869919ca7404aR14-R72">https://github.com/jamesmunns/cassette/pull/3/files#diff-ed3100414beca7e0d41c4f7a0765209dd2430a54dc6f3287355869919ca7404aR14-R72</a></p>



<a name="237393872"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/237393872" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#237393872">(May 04 2021 at 20:37)</a>:</h4>
<p>Hm, I might have some ideas how to avoid the unsafe pinning but it requires the <code>pin_static_ref</code> feature.<br>
Alternatively, it might be sound to initialize <code>LeakBox&lt;'static, MaybeUninit&lt;T&gt;&gt;</code> into a <code>Pin&lt;LeakBox&lt;'static, T&gt;&gt;</code> by writing a T.<br>
This works for static with the same correctness argument as std's pin_static_ref.</p>



<a name="237394051"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/237394051" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#237394051">(May 04 2021 at 20:38)</a>:</h4>
<p>And can you describe a bit more detailed how <code>unsize</code> did not work? Was it just the unpublished integration?</p>



<a name="237412978"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/237412978" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Munns <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#237412978">(May 04 2021 at 22:53)</a>:</h4>
<p>Full disclosure, I'm not <em>super</em> sure what I needed to be doing. I actually realized that I'm not sure I even needed unsize, as I was able to do the coersion directly?</p>



<a name="237506062"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/237506062" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#237506062">(May 05 2021 at 14:40)</a>:</h4>
<p>You'd need <code>unsize</code>for unsizing <code>LeakBox&lt;T&gt;</code> to <code>LeakBox&lt;dyn Future&lt;..&gt;&gt;</code>. But if you can make due with the reference type, for which coercion is implemented in std, then you do not need to create.</p>



<a name="237506224"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/why%20does%20bbqueue%20use%20GenericArray%3F/near/237506224" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/why.20does.20bbqueue.20use.20GenericArray.3F.html#237506224">(May 05 2021 at 14:41)</a>:</h4>
<p>I'll add some more examples to <code>unsize</code> as it's getting used more often.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>